<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>邀请有礼</title>
		<meta name="viewport" content="width=device-width, initial-scale=0.5, minimum-scale=0.5, maximum-scale=0.5, user-scalable=no,viewport-fit=cover">
		<meta name="format-detection" content="telephone=no">
		<meta name="renderer" content="webkit">
		<meta http-equiv="Cache-Control" content="no-siteapp" />
		<link rel="stylesheet" href="../../css/common.css" />
		<script type="application/javascript" src="../../js/common/static_common.js"></script>
		<script type="text/javascript" src="../../js/common/plus_common.js"></script>
		<style>
			#app{
				font-size: 28px;
			}
			.container.data-v-73112ec3 {
			    height: 93.5%;
			    width: 100%;
			    box-sizing: border-box;
			    display: flex;
			    flex-direction: column;
				position: absolute;
				top:6.5%
			}
			.text{
				margin-top:400px ;
				width: 100%;
				height: 200px;
				padding-left: 20px;
			}
			.warnText{
				color:#FF0000;
				font-size: 34px;
			}
			.text-title{
				font-size: 32px;
				color:#FFFFFF;
				font-weight: bolder;
				font-family: "microsoft yahei";
			}
			.text-description{
				color: #FFFFFF;
				padding-right: 20px;
			}
		</style>
	</head>
	<body>
		<span id="app">
			<header title="邀请有礼"></header>
			<div class="_div data-v-73112ec3 container" style="overflow-x: hidden;background-image: url(../../images/share_bg.png); 
			background-repeat: no-repeat;background-size:100% ;">
				<img src="../../images/share_user.png" style="width: 90%;position: fixed;bottom: 10%;left: 5%;" onclick="shareWeb()">
			</div>
		</span>
	</body>
	<script>
		var shares = null;
		var sweixin = null;
		var buttons = [{
				title: '我的好友',
				extra: {
					scene: 'WXSceneSession'
				}
			},
			{
				title: '朋友圈',
				extra: {
					scene: 'WXSceneTimeline'
				}
			}
		];
		// H5 plus事件处理
		function plusReady() {
			updateSerivces();
		}
		if (window.plus) {
			plusReady();
		} else {
			document.addEventListener('plusready', plusReady, false);
		}
		/**
		 * 更新分享服务
		 */
		function updateSerivces() {
			plus.share.getServices(function(s) {
				shares = {};
				for (var i in s) {
					var t = s[i];
					shares[t.id] = t;
				}
				sweixin = shares['weixin'];
			}, function(e) {
				outSet('获取分享服务列表失败：' + e.message);
			});
		}
	
		// 分享文本 
		function shareText() {
			var msg = {
				type: 'text',
				content: text_content.value
			};
			sweixin ? plus.nativeUI.actionSheet({
				title: '分享文本到微信',
				cancel: '取消',
				buttons: buttons
			}, function(e) {
				(e.index > 0) && share(sweixin, msg, buttons[e.index - 1]);
			}) : plus.nativeUI.alert('当前环境不支持微信分享操作!');
		}
	
		// 分享网页
		function shareWeb() {
			var msg = {
				type: 'web',
				thumbs: ['_www/logo.png']
			};
			var userData = localStorage.getItem("user_data");
			var userId = "";
			if(userData){
				userId = JSON.parse(userData).userId;
			}
			msg.href = "https://mjz.yitavc.com:88/mjzapp/html/mine/share_get.html?shareUserId="+userId;
			msg.title = "新人注册领100积分 享积分购物";
			content = "老妹！我这里有一个很好用的app！"+"\n点击进入页面 输入手机号并注册即可领取100积分唷！积分可购物呢！\n"
			msg.content = content;
			sweixin ? plus.nativeUI.actionSheet({
				title: '分享网页到微信',
				cancel: '取消',
				buttons: buttons
			}, function(e) {
				(e.index > 0) && share(sweixin, msg, buttons[e.index - 1]);
			}) : $(document).dialog({
				type:'confirm',
				titleText:"分享商品",
				position:'center',
				content:"亲！请使用app或者小程序分享唷！立即下载app？",
				buttonTextConfirm:"想要",
				buttonTextCancel:"算了",
				onClickConfirmBtn:function(){
					window.location.href="https://app.meijiangzi.com/static/mjzapp.html";
				},
			});
		}
	
		// 分享
		function share(srv, msg, button) {
			console.log('分享操作：');
			if (!srv) {
				outLine('无效的分享服务！');
				return;
			}
			button && (msg.extra = button.extra);
			// 发送分享
			if (srv.authenticated) {
				console.log('---已授权---');
				doShare(srv, msg);
			} else {
				console.log('---未授权---');
				srv.authorize(function() {
					doShare(srv, msg);
				}, function(e) {
					console.log('认证授权失败：' + JSON.stringify(e));
				});
			}
		}
		// 发送分享
		function doShare(srv, msg) {
			console.log(JSON.stringify(msg));
			srv.send(msg, function() {
				console.log('分享到"' + srv.description + '"成功！');
			}, function(e) {
				console.log('分享到"' + srv.description + '"失败: ' + JSON.stringify(e));
			});
		}
		// 解除授权
		function cancelAuth() {
			console.log('解除授权：');
			if (sweixin) {
				if (sweixin.authenticated) {
					console.log('取消"' + sweixin.description + '"');
				}
				sweixin.forbid();
			} else {
				console.log('当前环境不支持微信分享操作!');
			}
		}
	</script>
</html>